using System;
using System.Collections.Generic;
using System.Text;

namespace UMC.WorkFlow
{
    class EventInstance : InstanceEvent
    {
        public EventInstance()
        {
            eventTable = new System.Collections.Generic.Dictionary<string, System.Delegate>
            {
                { "OnApproved", null },
                { "OnBeginProcess", null },
                { "OnCompleted", null },
                { "OnEndProcess", null },
                { "OnRejected", null },
                { "OnSubmitted", null },
                { "OnLocked", null },
                { "OnPassLayer", null }
            };
            //eventTable.Add("OnTriggerOff", null);
        }

        private System.Collections.Generic.Dictionary<string, System.Delegate> eventTable;
        event TaskEvent InstanceEvent.OnApproved
        {
            add
            {
                eventTable["OnApproved"] = (TaskEvent)eventTable["OnApproved"] + value;
            }
            remove
            {
                eventTable["OnApproved"] = (TaskEvent)eventTable["OnApproved"] - value;

            }
        }

        event TaskEvent InstanceEvent.OnBeginProcess
        {
            add
            {
                eventTable["OnBeginProcess"] = (TaskEvent)eventTable["OnBeginProcess"] + value;
            }
            remove
            {
                eventTable["OnBeginProcess"] = (TaskEvent)eventTable["OnBeginProcess"] - value;

            }
        }

        event TaskEvent InstanceEvent.OnCompleted
        {
            add
            {
                eventTable["OnCompleted"] = (TaskEvent)eventTable["OnCompleted"] + value;
            }
            remove
            {
                eventTable["OnCompleted"] = (TaskEvent)eventTable["OnCompleted"] - value;
            }
        }

        event TaskEvent InstanceEvent.OnEndProcess
        {
            add
            {
                eventTable["OnEndProcess"] = (TaskEvent)eventTable["OnEndProcess"] + value;
            }
            remove
            {
                eventTable["OnEndProcess"] = (TaskEvent)eventTable["OnEndProcess"] - value;
            }
        }

        event TaskEvent InstanceEvent.OnRejected
        {
            add
            {
                eventTable["OnRejected"] = (TaskEvent)eventTable["OnRejected"] + value;
            }
            remove
            {
                eventTable["OnRejected"] = (TaskEvent)eventTable["OnRejected"] - value;
            }
        }

        event TaskEvent InstanceEvent.OnSubmitted
        {
            add
            {
                eventTable["OnSubmitted"] = (TaskEvent)eventTable["OnSubmitted"] + value;
            }
            remove
            {
                eventTable["OnSubmitted"] = (TaskEvent)eventTable["OnSubmitted"] - value;
            }
        }

        event TaskEvent InstanceEvent.OnLocked
        {
            add
            {
                eventTable["OnLocked"] = (TaskEvent)eventTable["OnLocked"] + value;
            }
            remove
            {
                eventTable["OnLocked"] = (TaskEvent)eventTable["OnLocked"] - value;
            }
        }

        event TaskEvent InstanceEvent.OnPassLayer
        {
            add
            {
                eventTable["OnPassLayer"] = (TaskEvent)eventTable["OnPassLayer"] + value;
            }
            remove
            {
                eventTable["OnPassLayer"] = (TaskEvent)eventTable["OnPassLayer"] - value;
            }
        }
        public void RaiseEvent(string eventKey, TaskInstance task, InstanceEventArgs e)
        {
            TaskEvent handler2;
            if (null != (handler2 = (TaskEvent)eventTable[eventKey]))
            {
                handler2(task, e);
            }
        }



    }
}
